/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * alterarAnoSemestre.java
 *
 * Created on 18/08/2011, 20:07:08
 */
package siga.visao;

import java.sql.SQLException;
import javax.swing.JOptionPane;
import siga.banco.conexao;

/**
 *
 * @author rafaelfrasson
 */
public class alterarAnoSemestre extends javax.swing.JDialog {
    public boolean finaliza = false;
    /** Creates new form alterarAnoSemestre */
    public alterarAnoSemestre(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jcAnoSemestre = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterar Ano/Semestre");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Ano/Semestre:");
        jLabel1.setName("jLabel1"); // NOI18N

        jcAnoSemestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ano/semestre" }));
        jcAnoSemestre.setName("jcAnoSemestre"); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/salvar_32x32.png"))); // NOI18N
        jButton1.setToolTipText("Salvar");
        jButton1.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/sair_32x32.png"))); // NOI18N
        jButton2.setToolTipText("Cancelar");
        jButton2.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addComponent(jcAnoSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcAnoSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        carregaAnoSemestre();
    }//GEN-LAST:event_formWindowOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        index.periodo.add(0,jcAnoSemestre.getSelectedItem().toString().substring(0, 4));
        index.periodo.add(1,jcAnoSemestre.getSelectedItem().toString().substring(5, 6));
        finaliza=true;
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void carregaAnoSemestre(){
        try {
            conexao.Query("select ano,semestre from grade_turma where cod_emp="+index.cod_emp+" group by ano,semestre order by ano DESC, semestre DESC");
            jcAnoSemestre.removeAllItems();
            while(conexao.rs.next()){
                jcAnoSemestre.addItem(conexao.rs.getString("ano")+"/"+conexao.rs.getString("semestre"));
            }
         
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JComboBox jcAnoSemestre;
    // End of variables declaration//GEN-END:variables
}
